package com.mth480.rebasedownloader;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;

/**
 * @author jake almer
 */
public class updaterGUI extends JDialog {
	JDialog thisDialog = this;
	public updaterGUI(Frame owner) {
		super(owner);
		initComponents();
		this.setAlwaysOnTop(true);
	}

//	public updaterGUI(Dialog owner) {
//		super(owner);
//		initComponents();
//	}
	
	public void AddToLog(String s){
		textArea1.append(" "+s+"\n\r");
	}
	public void setLastLineOfLog(String s){
		String oldtext = textArea1.getText();
		oldtext = oldtext.substring(0, oldtext.lastIndexOf('\n'));
		textArea1.setText(oldtext+"\n\r "+s);
	}

	private void initComponents() {

		dialogPane = new JPanel();
		contentPanel = new JPanel();
		textField1 = new JLabel();
		scrollPane1 = new JScrollPane();
		textArea1 = new JTextArea();
		buttonBar = new JPanel();
		okButton = new JButton();
		progressBar = new JProgressBar();

		//======== this ========
		setTitle("Updating Rebase Enzyme Data...");
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		//======== dialogPane ========
		{
			dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));

			dialogPane.setLayout(new BorderLayout());

			//======== contentPanel ========
			{
				contentPanel.setLayout(null);

				//---- label ----
				textField1.setText("Updating Rebase Enzyme Data...");
				textField1.setFont(new Font("Tahoma", Font.PLAIN, 22));
				contentPanel.add(textField1);
				textField1.setBounds(new Rectangle(new Point(0, 5), textField1.getPreferredSize()));

				// progressBar
				contentPanel.add(progressBar);
				progressBar.setBounds(0,40, 330, 15);
				
				//======== scrollPane1 ========
				{
					scrollPane1.setViewportView(textArea1);
				}
				contentPanel.add(scrollPane1);
				textArea1.setEditable(false);
				scrollPane1.setBounds(0, 60, 330, 325);

				{ // compute preferred size
					Dimension preferredSize = new Dimension();
					for(int i = 0; i < contentPanel.getComponentCount(); i++) {
						Rectangle bounds = contentPanel.getComponent(i).getBounds();
						preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
						preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
					}
					Insets insets = contentPanel.getInsets();
					preferredSize.width += insets.right;
					preferredSize.height += insets.bottom;
					contentPanel.setMinimumSize(preferredSize);
					contentPanel.setPreferredSize(preferredSize);
				}
			}
			dialogPane.add(contentPanel, BorderLayout.CENTER);

			//======== buttonBar ========
			{
				buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
				buttonBar.setLayout(new GridBagLayout());
				((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
				((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};

				//---- cancelButton ----
				okButton.setText("Ok");
				okButton.setEnabled(false);
				buttonBar.add(okButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 0), 0, 0));
				okButton.addActionListener(
					new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							thisDialog.setVisible(false);
						}
					}
				);
			}
			dialogPane.add(buttonBar, BorderLayout.SOUTH);
		}
		contentPane.add(dialogPane, BorderLayout.CENTER);
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - jake almer
	private JPanel dialogPane;
	private JPanel contentPanel;
	private JLabel textField1;
	private JScrollPane scrollPane1;
	private JTextArea textArea1;
	private JPanel buttonBar;
	public JButton okButton;
	public JProgressBar progressBar;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
}
